﻿using B.S.Packaged.ErrorCode;
using B.S.Packaged.WebAPI.Write.Applications.Commands.MaterialPreparation;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Packaged.WebAPI.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialPreparationController : ControllerBase
    {

        private readonly IMediator mediator;

        public MaterialPreparationController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加物料备料操作
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<APIResult<int>> Handle(AddMaterialPreparationCommand request, CancellationToken cancellationToken)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 删除物料备料操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> DelMaterialPreparation([FromBody] DeleteMaterialPreparationCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改物料备料功鞥
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UpdateMaterialPreparation(UpdateMaterialPreparationCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
